/**
 * file
 */
package com.tdkj.action.front.member.informationManagement;

import java.sql.Timestamp;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.tdkj.action.BaseAction;
import com.tdkj.model.information.BeanBaseInfo;
import com.tdkj.model.information.BeanInfoComment;
import com.tdkj.model.information.BeanInfoReply;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.information.IBeanBaseInfoService;
import com.tdkj.service.information.IBeanInfoCommentService;
public class InfoCommentAction extends BaseAction {
	private Long id;//信息id
	private Long cid;//评论id
	private Long rid;//回复id
	private String mt;
	private String reply_content;
	private BeanInfoComment comment;
	private BeanInfoReply reply;
	private IBeanInfoCommentService commentService;
	private IBeanBaseInfoService beanBaseInfoService;
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getCid() {
		return cid;
	}

	public void setCid(Long cid) {
		this.cid = cid;
	}

	public Long getRid() {
		return rid;
	}

	public void setRid(Long rid) {
		this.rid = rid;
	}
	
	public String getMt() {
		return mt;
	}

	public void setMt(String mt) {
		this.mt = mt;
	}

	public String getReply_content() {
		return reply_content;
	}

	public void setReply_content(String replyContent) {
		reply_content = replyContent;
	}

	public BeanInfoComment getComment() {
		return comment;
	}

	public void setComment(BeanInfoComment comment) {
		this.comment = comment;
	}
	public BeanInfoReply getReply() {
		return reply;
	}

	public void setReply(BeanInfoReply reply) {
		this.reply = reply;
	}

	public IBeanInfoCommentService getCommentService() {
		return commentService;
	}

	@Resource
	public void setCommentService(IBeanInfoCommentService commentService) {
		this.commentService = commentService;
	}
	
	public IBeanBaseInfoService getBeanBaseInfoService() {
		return beanBaseInfoService;
	}
	@Resource
	public void setBeanBaseInfoService(IBeanBaseInfoService beanBaseInfoService) {
		this.beanBaseInfoService = beanBaseInfoService;
	}

	public String findInfos(){
		BeanUser u=this.getCurrentUser();
		Criteria criteria = this.createCriteria(BeanBaseInfo.class);
		criteria.add(Restrictions.eq("user", u))
		.add(Restrictions.eq("status", "已审核"))
		.addOrder(Order.desc("createtime"));// 对状态进行排序
		this.queryByPage(criteria, "infoCommentAction!findInfos.action", 15);
		return "infolist";
	}
	public String findComment2info(){
		BeanBaseInfo b=beanBaseInfoService.findById(this.getId(), BeanBaseInfo.class);
		Criteria criteria = this.createCriteria(BeanInfoComment.class)
		.add(Restrictions.eq("baseinfo",b))
		.add(Restrictions.eq("status", "已审核"))
		.addOrder(Order.desc("createtime"));// 对状态进行排序
		this.queryByPage(criteria, "infoCommentAction!findComment2info.action",15);
		return "comment2info";
	}
	public String findComment2reply(){
		BeanUser u=this.getCurrentUser();
		Criteria criteria = this.createCriteria(BeanInfoComment.class);
		criteria.add(Restrictions.eq("user",u))
		.add(Restrictions.eq("status", "已审核"))
		.addOrder(Order.asc("replystatus"));// 对状态进行排序
		this.queryByPage(criteria, "infoCommentAction!findComment2reply.action", 15);
		return "comment2reply";
	}
	public String findReplys(){
		BeanInfoComment comment=commentService.findById(this.getCid(), BeanInfoComment.class);
		Criteria criteria = this.createCriteria(BeanInfoReply.class)
		.add(Restrictions.eq("status", "已审核"))
		.add(Restrictions.eq("comment",comment))
		.addOrder(Order.desc("createtime"));// 对状态进行排序
		this.queryByPage(criteria, "infoCommentAction!findReplys.action", 15);
		return "replylist";
	}
	public String findReply(){
		reply=commentService.findById(this.getRid(), BeanInfoReply.class);
		return "replycontent";
	}
	public String findReplyAddPage(){
		comment=commentService.findById(this.getCid(), BeanInfoComment.class);
		return "replyAddPage";
	}
	
	//回复评论
	public String addReply(){
		comment=commentService.findById(this.getCid(), BeanInfoComment.class);
		comment.setReplystatus("已回复");
		commentService.saveOrUpdate(comment, BeanInfoComment.class);
		cid=this.getCid();
		if(this.getReply_content()==null||this.getReply_content().equals("")){
			this.addFieldError("contentVlidate", "信息不能为空！");
		}
		BeanUser user=this.getCurrentUser();
		BeanInfoReply reply=new BeanInfoReply();
		reply.setContent(this.getReply_content());
		reply.setCreatetime(new Timestamp(System.currentTimeMillis()));
		beanBaseInfoService.replyCommment(user.getId(),this.getCid(),reply);
		return findReplyAddPage();
	}
	
}
